package util

import (
	"fmt"
	"gorm.io/driver/mysql"
	g "gorm.io/gorm"
	"gorm.io/gorm/logger"
)

const TencentClub = "tencentclub"
const Xzaims = "xzaims"
const Hello = "hello"

var db *g.DB
var err error

func GetLocalMysql(dbName string) *g.DB {
	dsn := ""
	switch dbName {
	case Xzaims:
		dsn = "root:123456@tcp(127.0.0.1:3306)/xzaims?charset=utf8&parseTime=True&loc=Local"
		break
	case TencentClub:
		dsn = "root:123456@tcp(127.0.0.1:3306)/club?charset=utf8&parseTime=True&loc=Local"
		break
	case Hello:
		dsn = "root:123456@tcp(127.0.0.1:3306)/hello?charset=utf8&parseTime=True&loc=Local"
		break
	default:
		dsn = "root:123456@tcp(127.0.0.1:3306)/xzaims?charset=utf8&parseTime=True&loc=Local"
		break
	}
	db, err = g.Open(mysql.Open(dsn), &g.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	if err != nil {
		fmt.Println("连接本地db失败", err)
	}
	fmt.Println("连接本地db成功:", dbName, db)
	return db
}
